home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / ASTRONOM / H139.ZIP / UI101.ZIP / IO / UI / UI_GETS.C < prev    next >
C/C++ Source or Header  |  1991-11-04  |  3KB  |  128 lines

  1. /****************************************************************
  2.  
  3.     ui_gets.c       gets function for
  4.             The Bywater Graphical User Interface
  5.  
  6.             Copyright (c) 1991, Ted A. Campbell
  7.  
  8.             Bywater Software
  9.             P. O. Box 4023 
  10.             Duke Station 
  11.             Durham, NC  27706
  12.  
  13.             email: tcamp@hercules.acpub.duke.edu
  14.  
  15.     Copyright and Permissions Information:
  16.  
  17.     All U.S. and international copyrights are claimed by the
  18.     author. The author grants permission to use this code
  19.     and software based on it under the following conditions:
  20.     (a) in general, the code and software based upon it may be 
  21.     used by individuals and by non-profit organizations; (b) it
  22.     may also be utilized by governmental agencies in any country,
  23.     with the exception of military agencies; (c) the code and/or
  24.     software based upon it may not be sold for a profit without
  25.     an explicit and specific permission from the author, except
  26.     that a minimal fee may be charged for media on which it is
  27.     copied, and for copying and handling; (d) the code must be 
  28.     distributed in the form in which it has been released by the
  29.     author; and (e) the code and software based upon it may not 
  30.     be used for illegal activities. 
  31.  
  32. ****************************************************************/
  33.  
  34. #include "stdio.h"
  35. #include "ctype.h"
  36. #include "gr.h"
  37. #include "kb.h"
  38. #include "ui.h"
  39.  
  40. #define    BACKSPACE    8
  41. #define    CURSOR        '_'
  42.  
  43. ui_wait()
  44.     {
  45.     register int carry_on;
  46.     static int x_pos, y_pos, b_stat;
  47.  
  48.     carry_on = TRUE;
  49.     while( carry_on == TRUE )
  50.         {
  51.         if ( kb_rxstat() == TRUE )
  52.             {
  53.             return kb_rx();
  54.             }
  55.         if ( gr_ismouse == TRUE )
  56.             {
  57.             if ( gr_mouse( SAMPLE, &x_pos, &y_pos, &b_stat ) == TRUE )
  58.                 {
  59.                 gr_mouse( WAIT, &x_pos, &y_pos, &b_stat );
  60.                 gr_mouse( WAIT, &x_pos, &y_pos, &b_stat );
  61.                 return TRUE;
  62.                 }
  63.             }
  64.         ui_poll();
  65.         }
  66.     }
  67.  
  68. ui_getch()
  69.     {
  70.     while( kb_rxstat() == FALSE )
  71.         {
  72.         ui_poll();
  73.         }
  74.     return kb_rx();
  75.     }
  76.  
  77. ui_gets( window, x, y, maxlength, buffer, display, foreground, background  )
  78.     struct gr_window *window;
  79.     int x, y, maxlength, display, foreground, background;
  80.     char *buffer;
  81.     {
  82.     register int c, p;
  83.     char disp_string[ 128 ];
  84.  
  85.     if ( display == TRUE )
  86.         {
  87.         sprintf( disp_string, "%c", CURSOR );
  88.         gr_text( ui_screen, x, y, disp_string,
  89.             foreground, background );
  90.         }
  91.  
  92.     buffer[ 0 ] = 0;
  93.     c = p = 0;
  94.     while( ( c != CR ) && ( c != LF) && ( strlen( buffer ) < maxlength ))
  95.         {
  96.         c = ui_getch();
  97.         switch( c )
  98.             {
  99.             case BACKSPACE:
  100.                 --p;
  101.                 buffer[ p ] = 0;
  102.                 break;                
  103.             case CR:
  104.             case LF:
  105.                 break;
  106.             default:
  107.                 buffer[ p ] = c;
  108.                 ++p;
  109.                 buffer[ p ] = 0;
  110.                 break;
  111.             }
  112.         if ( display == TRUE )
  113.             {
  114.             sprintf( disp_string, "%s%c ", buffer, CURSOR );
  115.             gr_text( ui_screen, x, y, disp_string,
  116.                 foreground, background );
  117.             }
  118.         }
  119.  
  120.     if ( display == TRUE )
  121.         {
  122.         sprintf( disp_string, "%s ", buffer );
  123.         gr_text( ui_screen, x, y, disp_string,
  124.             foreground, background );
  125.         }
  126.  
  127.     }
  128.